import java.util.Scanner;
import java.util.Stack;

public class TheOperationOfStack {
    public static void main(String[] args) {
        Scanner scanner=new Scanner(System.in);
        int[] a=new int[5];
        int[] b=new int[5];
        for(int i=0;i<5;i++){
            a[i]=scanner.nextInt();
        }
        for(int j=0;j<5;j++){
            b[j]=scanner.nextInt();
        }
        System.out.println(IsPopOrder(a,b));
    }
    public static boolean IsPopOrder(int[] pushA,int[] popA){
        Stack<Integer> stack=new Stack<>();
        int push=0,out=0;
        while(out< popA.length){
            // 当栈空 或者 栈顶元素与待出栈元素不相等时候入栈
            while(stack.isEmpty()||stack.peek()!=popA[out]){
                //有元素时继续入栈
                if(push<pushA.length){
                    stack.push(pushA[push]);
                    push++;
                }else{
                    return false;
                }
            }
            stack.pop();
            out++;
        }
        return true;
    }
}
